package com.guxing.controller;


import com.guxing.authConfig.AuthConfig;
import com.guxing.config.*;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("user")
@RefreshScope
public class UserController {

    @Resource
    UserConfig userConfig;

    @Resource
    UserCustom1 userCustom1;

    @Resource
    UserCustom2 userCustom2;

    @Resource
    UserCustom3 userCustom3;

    @Resource
    UserCustom4 userCustom4;

    @Resource
    AuthConfig authConfig;

    @GetMapping("getUser")
    public String getUser(){

        // 配置读取，默认当前服务
        System.out.println("当前服务配置读取：");
        System.out.println(userConfig.getId());
        System.out.println(userConfig.getName());

        // 自定义配置读取（属性注解读取）
        System.out.println("自定义配置读取1：");
        System.out.println(userCustom1.getId());
        System.out.println(userCustom1.getName());

        // 自定义配置读取（nacos注解）
        System.out.println("自定义配置读取2：");
        System.out.println(userCustom2.getId());
        System.out.println(userCustom2.getName());

        // 自定义配置读取（复杂对象，nacos注解）
        System.out.println("自定义配置读取3：");
        System.out.println(userCustom3.getId());
        System.out.println(userCustom3.getName());
        System.out.println(userCustom3.getOrder().getId());
        System.out.println(userCustom3.getOrder().getName());
        System.out.println(userCustom3.getOrder().getQuantity());
        System.out.println(userCustom3.getOrder().getAmount());

        // 自定义配置读取（json格式,nacos注解）
        System.out.println("自定义配置读取4(json)：");
        System.out.println(userCustom4.getId());
        System.out.println(userCustom4.getName());

        // 复杂配置读取（auth，nacos注解）
        System.out.println(authConfig.toString());

        return "hello world";
    }

}
